package com.htl.线程.sleep_wait;

import java.util.concurrent.TimeUnit;

/**
 *  二、如果 synchronized 修饰静态方法，则锁定的就是类，无论多少个对象调用，都会同步。
 */

public class Synchronized02 {
    public static void main(String[] args) {
        Date2 date1 = new Date2();
        Date2 date2 = new Date2();
        new Thread(()->{
            date1.func1();
        }).start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            date2.func2();
        }).start();
    }
}

class Date2{
    public synchronized static void func1(){
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("1...");
    }
    public synchronized static void func2(){
        System.out.println("2...");
    }
}
